package edu.gu.hajo.gcl.cmd.impl;

import edu.gu.hajo.gcl.interp.IInterpreter;
import edu.gu.hajo.gcl.script.Script;

public final class WhileCmd extends AbstractCmd {

	public WhileCmd(IInterpreter interp) {
		super(interp);
	}

	public void execute() {
		
//		 TODO check #args
				
		while( true ){
			Script cond = new Script(args.get(0));
			interp.eval( cond );
			String result = interp.getResult();
			if( !result.equals("true")){
				break;
			}
			Script body = new Script(args.get(1));
			interp.eval(body);
		}
		// TODO this is as the spec says but why??
		// Differs from if?
		interp.setResult("");
	}
}
